package com.miraeasset.www.sitemap;

import java.io.InputStream;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;

public class SiteMapTag extends TagSupport {
	private static final long serialVersionUID = 1075203140441245891L;
	@Override
	public int doStartTag() throws JspException {
		final String filepath = "/WEB-INF/sitemap.xml";
		   try {
			   HttpServletRequest request = ((HttpServletRequest)pageContext.getRequest());
			   InputStream docStream = request.getSession().getServletContext().getResourceAsStream(filepath);
			   SiteMap sitemap = new SiteMap(docStream);
			   sitemap.setDivideString(" < ");
			   super.pageContext.getOut().print(sitemap.render(request.getRequestURI()));
	        } catch (Exception ex) {
	            throw new JspTagException("SiteMapTag: " + ex.getMessage());
	        }
	        return SKIP_BODY; 
	}
}